package com.project.projectdemo.conf.task;

import java.util.concurrent.Executor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**、
 * 多线程定时任务配置类
 * @author MECHREVO
 *
 */

@Configuration
//开启异步
@EnableAsync
//开启定时任务
@EnableScheduling
public class AsyncConfig {
     
    private int corePoolSize = 10;
    private int maxPoolSize = 200;
    private int queueCapacity = 30;
    @Bean
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //核心线程数
        executor.setCorePoolSize(corePoolSize);
        //最大线程数
        executor.setMaxPoolSize(maxPoolSize);
        //队列大小 
        executor.setQueueCapacity(queueCapacity);
        executor.initialize();
        return executor;
    }
}